/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var deleteDuplicates = function (head) {
  let ans = []
  while (head) {
    ans.push(new ListNode(head.val))
    head = head.next
  }
  if (!ans.length) return null;
  for (var i = ans.length; i--;) {
    if (i && ans[i].val === ans[i - 1].val)
      ans.splice(i, 1);
  }
  for (let i = 0; i < ans.length - 1; i++) {
    ans[i].next = ans[i + 1]
  }
  return ans[0]
};